package com.miles.pushups;

import com.miles.pushups.R;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Main extends Activity {
	
//	SharedPreferences mySharedPreferences = getSharedPreferences("MY_PREFS",Activity.MODE_PRIVATE);

	Button W1D1;
	Button W1D2;
	Button W1D3;
	Button W2D1;
	Button W2D2;
	Button W2D3;
	Button W3D1;
	Button W3D2;
	Button W3D3;
	Button W4D1;
	Button W4D2;
	Button W4D3;
	Button W5D1;
	Button W5D2;
	Button W5D3;
	Button W6D1;
	Button W6D2;
	Button W6D3;
	TextView currentLevel;
	@Override
    public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);
	    	    
	    SharedPreferences mySharedPreferences = getSharedPreferences("MY_PREFS",Activity.MODE_PRIVATE);
	    currentLevel = (TextView)findViewById(R.id.level);
	    currentLevel.setText("Current Level: "+ (mySharedPreferences.getInt("level", 0)+1));
	    W1D1 = (Button)findViewById(R.id.W1D1);
	    W1D1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week1Day1.class);
				startActivity(intent);
			}
		});
	    W1D2 = (Button)findViewById(R.id.W1D2);
	    W1D2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week1Day2.class);
				startActivity(intent);
			}
		});
	    W1D3 = (Button)findViewById(R.id.W1D3);
	    W1D3.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week1Day3.class);
				startActivity(intent);
			}
		});
	    
	    W2D1 = (Button)findViewById(R.id.W2D1);
	    W2D1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week2Day1.class);
				startActivity(intent);
			}
		});
	    W2D2 = (Button)findViewById(R.id.W2D2);
	    W2D2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week2Day2.class);
				startActivity(intent);
			}
		});
	    W2D3 = (Button)findViewById(R.id.W2D3);
	    W2D3.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week2Day3.class);
				startActivity(intent);
			}
		});
	    
	    
	    W3D1 = (Button)findViewById(R.id.W3D1);
	    W3D1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week3Day1.class);
				startActivity(intent);
			}
		});
	    W3D2 = (Button)findViewById(R.id.W3D2);
	    W3D2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week3Day2.class);
				startActivity(intent);
			}
		});
	    W3D3 = (Button)findViewById(R.id.W3D3);
	    W3D3.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week3Day3.class);
				startActivity(intent);
			}
		});
	    
	    W4D1 = (Button)findViewById(R.id.W4D1);
	    W4D1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week4Day1.class);
				startActivity(intent);
			}
		});
	    W4D2 = (Button)findViewById(R.id.W4D2);
	    W4D2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week4Day2.class);
				startActivity(intent);
			}
		});
	    W4D3 = (Button)findViewById(R.id.W4D3);
	    W4D3.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week4Day3.class);
				startActivity(intent);
			}
		});
	    
	    W5D1 = (Button)findViewById(R.id.W5D1);
	    W5D1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week5Day1.class);
				startActivity(intent);
			}
		});
	    W5D2 = (Button)findViewById(R.id.W5D2);
	    W5D2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week5Day2.class);
				startActivity(intent);
			}
		});
	    W5D3 = (Button)findViewById(R.id.W5D3);
	    W5D3.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week5Day3.class);
				startActivity(intent);
			}
		});
	    
	    W6D1 = (Button)findViewById(R.id.W6D1);
	    W6D1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week6Day1.class);
				startActivity(intent);
			}
		});
	    W6D2 = (Button)findViewById(R.id.W6D2);
	    W6D2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week6Day2.class);
				startActivity(intent);
			}
		});
	    W6D3 = (Button)findViewById(R.id.W6D3);
	    W6D3.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(Main.this,Week6Day3.class);
				startActivity(intent);
			}
		});
	    
	}
	
	public boolean onCreateOptionsMenu(Menu menu){
		super.onCreateOptionsMenu(menu);
		menu.add(0,0, Menu.NONE, R.string.menu1);
		menu.add(0,1, Menu.NONE, R.string.menu2);
		menu.add(0,2, Menu.NONE, R.string.menu3);
		return true;
	}
	
	public boolean onOptionsItemSelected(MenuItem item){
		super.onOptionsItemSelected(item);
		SharedPreferences mySharedPreferences = getSharedPreferences("MY_PREFS",Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = mySharedPreferences.edit();
		switch(item.getItemId()){
		case (0):
			// we have level 1
//			level = 0;
			editor.putInt("level", 0);
			editor.commit();
			currentLevel.setText("Current Level: "+ (mySharedPreferences.getInt("level", 0)+1));
			return true;
		case (1):
			// we have level 2
//			level = 1;
			editor.putInt("level", 1);
			editor.commit();
			currentLevel.setText("Current Level: "+ (mySharedPreferences.getInt("level", 0)+1));
			return true;
		case (2):
			// we have level 3
//			level = 2;
			editor.putInt("level", 2);
			editor.commit();
			currentLevel.setText("Current Level: "+ (mySharedPreferences.getInt("level", 0)+1));
			return true;
		}
		
		return false;
	}
}
